import React from 'react';
import { Modal, Descriptions } from 'antd';
import { getWordvec, } from '@/services/resource';
import Styles from '../../style.less'

class Detai extends React.Component {
    constructor(argus) {
        super(argus);

        this.state = {
            data: {}
        };
    }
    componentDidMount() {
        this.props.wordvecId && getWordvec(this.props.wordvecId).then(res => {
            if (res.retCode == '0') this.setState({ data: res.data })
        })
    }

    infoToParent(key) {
        this.props.callBack(key);
    }

    render() {
        const { isShowDetail, wordvecId, } = this.props;
        const { data, } = this.state;
        const dataName = {
            dim: '词维度',
            window: '窗口',
            minCount: '单词最小词频',
            negativeUsed: '是否采用负采样',
            negativeSampleNum: '负采样数量',
            iterNum: '迭代次数',
            wordvecName: '词向量'
        }
        const des = [];
        for (let k in data.wordvecConfig) {
            if (k !== 'wordvecName' && k !== 'sourceType' && k !== 'algorithm_id') {
                if (k === 'negativeUsed') {
                    des.push({ label: dataName[k], val: ['否', '是'][data.wordvecConfig[k] - 0] })
                } else {
                    des.push({ label: dataName[k], val: data.wordvecConfig[k] })
                }
            }
        }

        return <Modal
            title={`详情`}
            maskClosable={false}
            visible={isShowDetail}
            width={600}
            onCancel={this.infoToParent.bind(this, false)}
            footer={null}
        >
            <Descriptions column={1}>
                <Descriptions.Item label="词向量名称">{data && data.wordvecName}</Descriptions.Item>
                <Descriptions.Item label="训练类型">{['词向量', '语料'][data && data.sourceType - 0]}</Descriptions.Item>
                {
                    data.sourceType == 1 ?
                        des.map((v, i) => <Descriptions.Item key={i} label={v.label}>{v.val}</Descriptions.Item>)
                        : null
                }
            </Descriptions>
        </Modal>
    }
}


export default Detai;